# Makefile
# 简化开发流程的快捷命令

.PHONY: help install install-dev test lint format clean build doc

# 默认目标
help:
	@echo "可用的命令:"
	@echo "  install      - 安装生产依赖"
	@echo "  install-dev  - 安装开发依赖"
	@echo "  test         - 运行验收测试"
	@echo "  lint         - 运行代码质量检查"
	@echo "  format       - 自动格式化代码"
	@echo "  clean        - 清理缓存和临时文件"
	@echo "  build        - 构建发布包"
	@echo "  setup        - 设置 pre-commit 钩子"

# 安装依赖
install:
	pip install -e .

# 安装开发依赖
install-dev:
	pip install -e .
	pip install -r requirements.txt
	pip install black ruff isort bandit pydocstyle pre-commit pytest

# 运行验收测试
test:
	bash scripts/acceptance.sh

# 运行代码质量检查
lint:
	bash scripts/quality_check.sh

# 自动格式化代码
format:
	black .
	ruff check --fix .
	ruff format .
	isort .

# 清理
clean:
	rm -rf build/
	rm -rf dist/
	rm -rf *.egg-info/
	rm -rf .pytest_cache/
	rm -rf .ruff_cache/
	find . -type d -name __pycache__ -exec rm -rf {} +
	find . -type f -name "*.pyc" -delete
	find . -type f -name "*.pyo" -delete
	find . -type f -name ".coverage" -delete
	rm -rf outputs/test*
	rm -rf outputs/.cache

# 构建包
build: clean
	python -m build
	twine check dist/*

# 设置 pre-commit
setup:
	pre-commit install
	pre-commit install --hook-type commit-msg

# 验证 Schema
validate-schema:
	python schemas/scenes_schema.py examples/scence_text.json

# 验证所有模块
validate-modules:
	@python -c "from prompts.templates import PromptManager; print('✓ prompts 正常')" || exit 1
	@python -c "from utils.cache import CacheManager; print('✓ utils 正常')" || exit 1
	@python -c "from schemas.scenes_schema import validate_scenes_file; validate_scenes_file('examples/scence_text.json'); print('✓ schemas 正常')" || exit 1
	@echo "所有模块验证通过"

# 快速验证
quick-check: validate-modules
	@echo "运行快速检查..."
	@python markdown_to_video.py examples/example.md --dry-run --no-manim

# 开发者工作流
dev: install-dev setup
	@echo "开发环境设置完成"
	@echo "提示：运行 'make test' 验证功能，'make lint' 检查代码质量"
